<template>
	<div style="width: 100%;height: 100%">
		<index-preview v-if="screenAlias" :alias="screenAlias" :appId="screenAppId" :isMobile="isMobile" :isAuth="false"></index-preview>
		<a-modal
			:title="i18n('passwordValid','密码验证')"
			:visible="visible"
			:cancelText="$ti18('rxForm.closeBtn','关闭')"
			@ok="handleOk"
			@cancel="handleCancel"
		>
			<a-input-password  v-model="password"/>
		</a-modal>
	</div>
</template>

<script>
import ScreenViewManageApi from "@/api/screen/core/screen-view-manage.js";
import indexPreview from "@/views/modules/preview/index.vue";
export default {
	name: "share-preview",
	components:{
		indexPreview
	},
	data(){
		return{
			screenAlias:"",
      screenAppId:"",
			isMobile:false,
			password:"",
			visible:false,
		}
	},
	created() {
		this.init();
	},
	methods:{
		i18n(name, text, key) {
			return this.$ti18(name, text, "previewLang", key);
		},
		init(){
			//分享加密参数
			if(this.$route.params && this.$route.params.encryParams){
				let decryStr = window.atob(this.$route.params.encryParams); // 解码
				let paramStr=window.decodeURIComponent(decryStr);
				if(paramStr){
					this.encryParams=JSON.parse(paramStr);
					this.getByLinkShare(this.encryParams.alias,this.encryParams.appId);
				}
			}
		},
		getByLinkShare(alias,appId,password){
			ScreenViewManageApi.getByLinkShare(alias,appId,password).then(res=>{
				//验证密码
				if(res && res.data){
					if(res.data=="authPassword"){
						this.visible=true;
					}else if(res.data=="success"){
						this.visible=false;
						this.password="";
						this.screenAlias=alias;
            this.screenAppId=appId;
					}
				}
			});
		},
		handleOk(){
			this.getByLinkShare(this.encryParams.alias,this.encryParams.appId,this.password);
		},
		handleCancel(){
			this.visible=false;
		}
	}
}
</script>

<style scoped>

</style>
